﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;

namespace VNSoft
{
    public partial class Website : System.Web.UI.Page
    {
        Administrator.clsXuLy ex = new Administrator.clsXuLy();
        public string Host = System.Configuration.ConfigurationSettings.AppSettings["Host"].ToString();
        public string Site = System.Configuration.ConfigurationSettings.AppSettings["Site"].ToString();
        DataTable dts;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (string.IsNullOrEmpty((Request.QueryString["ID"])))
                {
                    pnList.Visible = true;
                    pnView.Visible = false;

                    dts = ex.GetData("cl_GetBaiViet_Website");
                    LoadBaiViet(dts, lbSanPham);
                }
                else
                {
                    pnList.Visible = false;
                    pnView.Visible = true;
                    string ID = Request.QueryString["ID"].ToString();
                    Guid gID = new Guid(ID);
                    SqlParameter[] p = new SqlParameter[1];
                    p[0] = new SqlParameter("@ID", gID);
                    p[0].SqlDbType = SqlDbType.UniqueIdentifier;

                    DataTable dt = ex.GetData("sp_BaiViet_ListByID", p);

                    if (dt.Rows.Count > 0)
                    {
                        lbTieuDe.Text = dt.Rows[0]["Title"].ToString();
                        Title = lbTieuDe.Text + " | DLT-Soft";
                        lbBody.Text = dt.Rows[0]["Body"].ToString();
                    }

                    HtmlMeta des = new HtmlMeta();
                    des.Name = "description";
                    des.Content = dt.Rows[0]["Description"].ToString();
                    Header.Controls.Add(des);

                    HtmlMeta key = new HtmlMeta();
                    key.Name = "keywords";
                    key.Content = dt.Rows[0]["KeySEO"].ToString();
                    Header.Controls.Add(key);

                    HtmlMeta region = new HtmlMeta();
                    region.Name = "geo.region";
                    region.Content = "VN";
                    Header.Controls.Add(region);

                    HtmlMeta place = new HtmlMeta();
                    place.Name = "geo.placename";
                    place.Content = "HaNoi";
                    Header.Controls.Add(place);

                    HtmlMeta lang = new HtmlMeta();
                    lang.Name = "language";
                    lang.Content = "VN";
                    Header.Controls.Add(lang);

                    HtmlMeta auth = new HtmlMeta();
                    auth.Name = "author";
                    auth.Content = Site;
                    Header.Controls.Add(auth);

                    HtmlMeta ogdes = new HtmlMeta();
                    ogdes.Attributes.Add("property", "og:description");
                    ogdes.Content = dt.Rows[0]["Description"].ToString();
                    Header.Controls.Add(ogdes);

                    HtmlMeta ogimg = new HtmlMeta();
                    ogimg.Attributes.Add("property", "og:image");
                    ogimg.Content = Host + dt.Rows[0]["Image"].ToString();
                    Header.Controls.Add(ogimg);

                    HtmlMeta ogkey = new HtmlMeta();
                    ogkey.Attributes.Add("property", "og:keywords");
                    ogkey.Content = dt.Rows[0]["KeySEO"].ToString();
                    Header.Controls.Add(ogkey);

                    HtmlMeta ogtype = new HtmlMeta();
                    ogtype.Attributes.Add("property", "og:type");
                    ogtype.Content = "website";
                    Header.Controls.Add(ogtype);

                    HtmlMeta ogsitename = new HtmlMeta();
                    ogsitename.Attributes.Add("property", "og:site_name");
                    ogsitename.Content = Site;
                    Header.Controls.Add(ogsitename);

                    HtmlMeta ogTitle = new HtmlMeta();
                    ogTitle.Attributes.Add("property", "og:title");
                    ogTitle.Content = lbTieuDe.Text;
                    Header.Controls.Add(ogTitle);

                    HtmlMeta ogurl = new HtmlMeta();
                    ogurl.Attributes.Add("property", "og:url");
                    ogurl.Content = HttpContext.Current.Request.Url.AbsoluteUri;
                    Header.Controls.Add(ogurl);

                    dts = ex.GetData("cl_GetBaiViet_Website_LienQuan");
                    lbLienquan.Text = "";
                    for (int i = 0; i < dts.Rows.Count; i++)
                    {
                        lbLienquan.Text += "<div><img src=\"" + Host + "image/arrow2.jpg\" />&nbsp;&nbsp;";
                        lbLienquan.Text += "<span>" + "<a href='" + Host + "thiet-ke-web/" + ex.ConvertToUnSign(dts.Rows[i]["Title"].ToString()) + "/" + dts.Rows[i]["ArticleID"].ToString().ToUpper() + ".html'" + ">" + dts.Rows[i]["Title"].ToString() + "</a></span></div>";
                    }
                }
            }
        }
        private void LoadBaiViet(DataTable dt, Label lb)
        {
            lb.Text = "";
            try
            {
                if (dt.Rows.Count > 0)
                {

                    lb.Text += "<table>";

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        lb.Text += "<tr><td width=\"195px\" valign=\"top\">";
                        lb.Text += "<a href='" + Host + "thiet-ke-web/" + ex.ConvertToUnSign(dt.Rows[i]["Title"].ToString()) + "/" + dt.Rows[i]["ArticleID"].ToString().ToUpper() + ".html'" + ">";
                        lb.Text += "<img class=\"anh\" width=\"195px\" height=\"125px\" alt='" + dt.Rows[i]["Title"].ToString() + "' src='" + Host + dt.Rows[i]["Image"].ToString() + "' ";
                        if (i > 0)
                            lb.Text += " style=\"margin-top: 10px;\"";
                        lb.Text += " /></a></td><td valign=\"top\"><div class=\"title\"";
                        if (i > 0)
                            lb.Text += "style=\"margin-top: 5px;\">";
                        lb.Text += "<a href='" + Host + "thiet-ke-web/" + ex.ConvertToUnSign(dt.Rows[i]["Title"].ToString()) + "/" + dt.Rows[i]["ArticleID"].ToString().ToUpper() + ".html'>" + dt.Rows[i]["Title"].ToString() + "</a>";
                        lb.Text += "</div><div class=\"description\">";
                        lb.Text += dt.Rows[i]["Description"].ToString();
                        lb.Text += "</div></td></tr>";
                    }
                    lb.Text += "</table>";

                }
            }
            catch { lb.Text = ""; }
        }
    }
}